<?php
$page = $control;
$eventListAjaxLink = $page->getAjaxLink('List Event',NULL,NULL,'weEvent/listEvent');
?>
<p><?php echo $eventListAjaxLink;?>
</p>
<?php
$addnewEvent = Yii::t('site','add newEvent');
$setupeventStr = Yii::t('site','Setup evnet');
$eventNameStr = Yii::t('site','Name');
$eventTitleStr = Yii::t('site','titl');
$descriptionStr = Yii::t('site','Description');
$start_timeStr = Yii::t('site','start time');
$end_timeStr = Yii::t('site','end time');
$event_creatorStr = Yii::t('site','event creator');
$event_messageStr = Yii::t('site','event_message');
$dataStr = Yii::t('site','data');
$statusStr = Yii::t('site','status');  
$screen = Blyn::app()->getCurrentNode()->getUIManager()->getCurrentScreen();
$app = Blyn::app()->getActiveApp();
$eventData= new BSeventFormModel();

$EventData= new BSResourceFormModel();
if (!empty($_POST)) {
    if(isset( $_POST['name' . $eventId]) )
    {
        $eventData->id = $eventId;
        $eventData->name = $_POST['name' . $eventId];
        $eventData->title = $_POST['title' . $eventId];        
        $eventData->description = $_POST['description' . $eventId];
        $eventData->start_time = $_POST['start_time' . $eventId];
        $eventData->end_time  = $_POST['end_time' . $eventId];
        $eventData->event_creator = $_POST['event_creator' . $eventId];
        $eventData->event_message = $_POST['event_message' . $eventId];
        $eventData->data = $_POST['data' . $eventId]; 
        $eventData->status = $_POST['status' . $eventId];      
    }
    else if($eventId>0) {
        $eventData->id = $eventId;
        $eventData->name = $event->name;
        $eventData->title = $event->title;
        $eventData->description = $event->description;
        $eventData->start_time = $event->start_time;
        $eventData->end_time  = $event->end_time;
        $eventData->event_creator = $event->event_creator;
        $eventData->event_message = $event->event_message;
        $eventData->data = $event->data; 
        $eventData->status = $event->status; 
    }
    
    if ($screen->isAjaxLinkClicked(array('ajaxLinkId' => 'link' . $eventId))) {
        if ($app instanceof BWeEvent) {
            $app->addevent($eventData);
            Yii::app()->end();
        }
    }
}
?>	
<script type="text/javascript">
$('body').on('hidden.bs.modal', '.modal', function () {
    $(this).removeData('bs.modal');
});
</script>

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3><?php echo $addnewEvent; ?></h3>
</div>
<div class="modal-body">
    <div class="tabbable tabs-right" style="margin-top: 15px;"> <!-- Only required for left/right tabs -->
        <ul class="nav nav-tabs" style="margin-bottom: 15px">
            <li class="active"><a href="#tab1<?php echo $eventId; ?>" data-toggle="tab"><?php echo $addBasicInfoStr; ?></a></li>
            <li><a href="#tab2<?php echo $eventId; ?>" data-toggle="tab"><?php echo $setupeventStr; ?></a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id="tab1<?php echo $eventId; ?>" style="min-height: 270px">
                <div class="well">
                    <label><?php echo $eventNameStr; ?>:</label>
                    <?php echo CHtml::activeTextField($eventData, 'name', array('name' => "name" . $eventId, 'placeholder' => 'Type name...', 'required' => true)); ?>
                    <label><?php echo $eventTitleStr; ?>:</label>
                    <?php echo CHtml::activeTextField($eventData, 'title', array('name' => "title" . $eventId, 'placeholder' => 'Type title...', 'required' => true)); ?>                
                    <label><?php echo $descriptionStr; ?>:</label>                
                    <?php echo CHtml::activeTextArea($eventData, 'description', array('name' => "description" . $eventId, 'placeholder' => 'Type description...')); ?>
                    <label><?php echo $start_timeStr; ?>:</label>
                    <?php echo CHtml::activeTextField($eventData, 'name', array('name' => "start_time" . $eventId, 'placeholder' => 'Type start_time...', 'required' => true)); ?>
                    <label><?php echo $end_timeStr; ?>:</label>
                    <?php echo CHtml::activeTextField($eventData, 'name', array('name' => "end_time" . $eventId, 'placeholder' => 'Type end_time...', 'required' => true)); ?>
                    <label><?php echo $event_creatorStr; ?>:</label>
                    <?php echo CHtml::activeTextField($eventData, 'name', array('name' => "event_creator" . $eventId, 'placeholder' => 'Type event_creator...', 'required' => true)); ?>
                    <label><?php echo $event_messageStr; ?>:</label>
                    <?php echo CHtml::activeTextField($eventData, 'name', array('name' => "event_message" . $eventId, 'placeholder' => 'Type event_message...', 'required' => true)); ?>
                    <label><?php echo $dataStr; ?>:</label>
                    <?php echo CHtml::activeTextField($eventData, 'name', array('name' => "data" . $eventId, 'placeholder' => 'Type data...', 'required' => true)); ?>
                    <label><?php echo $statusStr; ?>:</label>
                    <?php echo CHtml::activeTextField($eventData, 'name', array('name' => "status" . $eventId, 'placeholder' => 'Type status...', 'required' => true)); ?>
                </div>
            </div>
            
        </div>
    </div>

</div>     
<div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo Yii::t('site','Close'); ?></button>
    <?php
    echo $screen->getAjaxLink(Yii::t('site','Save changes'), array(
        'ajaxLinkId' => 'link' . $eventId,
        'ajaxContainerId' => 'myModal' . $eventId,
        'ajaxView' => array('addnewEvent', 'data' => array('eventId' => $eventId)),
        'htmlOptions' => array('class' => 'btn btn-primary'),
        'ajaxOptions' => array('complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal'.$eventId.'").modal("hide");$("#refreshIt").click();}')));
    ?>
</div>


